package NetworkCopy.IO;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerIO {
    public static void main(String[] args) throws IOException {

        try (
                ServerSocket serverSocket = new ServerSocket(7001);
                Socket socket = serverSocket.accept();
                InputStream is = socket.getInputStream();
                FileOutputStream fos = new FileOutputStream("dataTargetNetIO.bin");
                BufferedOutputStream bos = new BufferedOutputStream(fos)) {

            int bufferSize = socket.getReceiveBufferSize();

            byte[] bytes = new byte[bufferSize];
            int count;

            long start = System.currentTimeMillis();

            while ((count = is.read(bytes)) > 0) {
                bos.write(bytes, 0, count);
            }
            bos.flush();

            long end = System.currentTimeMillis();
            System.out.println("Time: " + (end - start) + " ms");
        }
    }
}

